/**********************************************************************
* Filename: Clube.java
* Created: 2012/04/30
* @author Fernando Brito e Abreu
**********************************************************************/
package org.bunny.businessLayer;

import java.util.Set;
import java.util.HashSet;

public class Clube{
	public static Set<Clube> allInstances = new HashSet<Clube>();
	
	private String nome;
	private Pais pais;
	
	/**********************************************************************
	* Default constructor
	**********************************************************************/
	public Clube(){
		allInstances.add(this);
	}
	
	/**********************************************************************
	* Parameterized constructor
	* @param nome the nome to initialize
	* @param pais the pais to initialize
	**********************************************************************/
	public Clube(String nome, Pais pais){
		this.nome = nome;
		this.pais = pais;
		allInstances.add(this);
	}
	
	/**********************************************************************
	* Standard attribute getter
	* @return the nome of the clube
	**********************************************************************/
	public String nome(){
		return nome;
	}
	
	/**********************************************************************
	* Standard attribute setter
	* @param nome the nome to set
	**********************************************************************/
	public void setNome(String nome){
		this.nome = nome;
	}
	
	/**********************************************************************
	* ONE2MANY getter for Clube[*] <-> Pais[1]
	* @return the pais of the clube
	**********************************************************************/
	public Pais pais(){
		return pais;
	}
	
	/**********************************************************************
	* ONE2MANY setter for Clube[*] <-> Pais[1]
	* @param pais the pais to set
	**********************************************************************/
	public void setPais(Pais pais){
		this.pais = pais;
	}
	
	/**********************************************************************
	* ONE2MANY getter for Clube[1] <-> Jogador[*]
	* @return the jogadores of the clube
	**********************************************************************/
	public Set<Jogador> jogadores(){
		Set<Jogador> result = new HashSet<Jogador>();
		for (Jogador x : Jogador.allInstances)
			if (x.clube()  ==  this)
				result.add(x);
		return result;
	}
	
	/**********************************************************************
	* ONE2MANY setter for Clube[1] <-> Jogador[*]
	* @param jogadores the jogadores to set
	**********************************************************************/
	public void setJogadores(Set<Jogador> jogadores){
		for (Jogador x : jogadores)
			x.setClube(this);
	}
	
	/**********************************************************************
	* User-defined operation specified in SOIL/OCL
	* @param nome the nome to set
	* @param pais the pais to set
	**********************************************************************/
//	public void inicializa(String nome, Pais pais){
//		//	TODO
//		this.nome = nome;
//		
//		//	self.nome := nome;
//		//	 insert (pais,self) into Pais_Clube;
//	}
	
	//	PRE-CONDITIONS (TODO)
	/*
	pre ClubeParametrosDefinidos
		(nome.isDefined and pais.isDefined)
	
	*/
	
	//	POST-CONDITIONS (TODO)
	/*
	post ClubeInicializado
		self.nome.isDefined
	
	*/
	
	/* (non-Javadoc)
	* @see java.lang.Object#toString()
	*/
	@Override
	/**********************************************************************
	* Object serializer
	**********************************************************************/
	public String toString(){
		return "Clube [nome=" + nome + ", pais=" + pais + "]\n";
	}
	
	//	-------------------------------------------------------------------------------
	//	INVARIANTS (TODO)
	/*
	inv NomeClubeRespeitaTamanho
		((self.nome.size > 2) and (self.nome.size < 64))
	
	inv NaoHaClubesRepetidos
		(Clube.allInstances->select(c : Clube | (c.nome = self.nome))->size = 1)
	
	*/
}
